<?php
/* 	These code was generated using phpCIGen v 0.1.a (21/04/2009)
	#zaqi 		zaqi.smart@gmail.com,http://zenzaqi.blogspot.com, 
    #songbee	mukhlisona@gmail.com
	#CV. Trust Solution, jl. Saronojiwo 19 Surabaya, http://www.ts.co.id
	
	+ Module  		: ganti password Controller
	+ Description	: For record controller process back-end
	+ Filename 		: C_tbl_ganti_pasword.php
 	+ Author  		: 
 	+ Created on 01/May/2009 06:35:27
	
*/

//class of tbl_m_warna
class C_update extends CI_Controller {

	//constructor
	function C_update(){
		parent::__construct();

		
		//$this->load->model('m_update', '', TRUE);
		$this->load->library('zip');
		checkLogin();
	}
	
	//set index
	function index(){
		$this->load->helper('asset');
		$this->load->view('main/v_update');
		
	}
	
	function fix_bug(){
		$file=$_FILES["namaFile"];
		$namaFile = $_FILES['namaFile']['name'];
		if(!file_exists("uploads")){
			mkdir("uploads");
		}
		$result=move_uploaded_file ($_FILES['namaFile']['tmp_name'],"./uploads/".$_FILES['namaFile']['name']);
		if($result){
			
			$zip = new ZipArchive;
			$res = $zip->open("./uploads/".$_FILES['namaFile']['name']);
			if ($res === TRUE) {
				$zip->extractTo("./");
				$zip->close();
				$filename="./update.sql";
				if(file_exists($filename)){
					$handle = fopen($filename,'r');
				    $contents = fread($handle, filesize($filename));
				    $contents =trim($contents,";");
				    $queries=split(";",$contents);
				    $this->m_konsolidasi->kosongkan();
				    foreach ($queries as $sql){
				    	$this->db->simple_query(trim($sql).";");
				    }
				    fclose($handle);
				}
			    
				echo '{"success":"true","msg":"Update berhasil"}';
				
			} else {
				echo '{"success":"false","msg":"Update gagal"}';
			}
						
		}else{
			echo '{"success":"false","msg":"Update gagal"}';
		}
	}
	
}
?>